package goliath;

import org.jbox2d.dynamics.Body;
import org.jbox2d.dynamics.World;
import org.jbox2d.dynamics.BodyDef;
import org.jbox2d.common.Vec2;
import org.jbox2d.collision.Shape;
import org.jbox2d.collision.ShapeDef;
import org.jbox2d.collision.MassData;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import pulpfizz.physics.PhysicsUtils;
import pulpfizz.physics.BodyUtils;

/**
 * Intermediate object that wraps a Body to provide serialization functionality.
 * @author will
 * @date Aug 9, 2008 3:00:13 PM
 */
public class BodyObject implements Serializable {
    public float x,y;
    public float angle;
    public float angularDamping;
    public List<ShapeObject> shapeList;

    public BodyObject(Body body) {
    }

    /**
     * Creates a new Body from this object, inserted into the specified World.
     * @param w
     * @return
     */
    public Body createBody(World w) {
        BodyDef b = new BodyDef();
        b.angle = angle;
        b.angularDamping = angularDamping;


        BodyDef bd = PhysicsUtils.newBodyDef();
        Body cb = w.createBody(bd);
        cb.setXForm(new Vec2(x, y), angle);

//        Shape curr = b.getShapeList();
//        for (int i = 0; i < b.m_shapeCount; ++i) {
//            ShapeDef shapeDef = BodyUtils.shapeToShapeDef(curr);
//            cb.createShape(shapeDef);
//            curr = curr.getNext();
//        }
//        MassData md = new MassData();
//        md.center = b.getLocalCenter();
//        md.I = b.m_I;
//        md.mass = b.getMass();
//        cb.setMass(md);
//        return cb;
//
        return null;
    }
    
}
